#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, k, b, d, n=0;
	cin>>a>>b>>d;
	for(int i = a;i <= b;i++)
	{
		if(i != 2 && i%2 == 0)
			continue; 
		int k = sqrt(i);
		int x = i;
		while(x)
		{
			if(x%10 == d) 
				break;
			else
				x = x/10;	
		}
		if(x)
		{
			int j;
			for(j=2;j<=k;j++)
				if(i%j==0)
					break;
			if(j>k)
				n++;
		}
	}
	cout<<n;
    return 0;
}
